package com.zw.yzk.kabu.mapper;

import com.zw.yzk.kabu.data.network.entity.GoodsDetailsEntity;
import com.zw.yzk.kabu.model.GoodsDetailsModel;
import com.zw.yzk.kabu.utils.CalculateUtils;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * Created by zhanwei on 2017/3/5.
 */

public class GoodsDetailsMapper {

    @Inject
    public GoodsDetailsMapper() {

    }


    public GoodsDetailsModel.Sku transferSku(GoodsDetailsEntity.Sku entity) {
        GoodsDetailsModel.Sku model = new GoodsDetailsModel.Sku();
        //库存
        model.setStock(entity.stock);
        // 型号组合id，productid_propertyid:modelid_...组合，需要酱每个属性里面的每一个型号都组合起来
        model.setSkuId(entity.skuId);
         // 原价
        model.setOriginalPrice(entity.originalPrice);
        // 优惠价
        model.setDiscountedPrice(entity.discountedPrice);
        //真实价格
        model.setPrice(CalculateUtils.getRealPrice(entity.originalPrice, entity.discountedPrice));
        return model;
    }

    public List<GoodsDetailsModel.Sku> transferSku(List<GoodsDetailsEntity.Sku> entityList) {
        List<GoodsDetailsModel.Sku> modelList = new ArrayList<>();
        if (entityList == null || entityList.isEmpty()) {
            return modelList;
        }
        for (GoodsDetailsEntity.Sku entity : entityList) {
            modelList.add(transferSku(entity));
        }
        return modelList;
    }

    public GoodsDetailsModel.Banner transferBanner(GoodsDetailsEntity.Banner entity) {
        GoodsDetailsModel.Banner model = new GoodsDetailsModel.Banner();
        //bannerId
        model.setBannerId(entity.bannerId);
        // 展示顺序
        model.setOrder(entity.order);
        // 图片
        model.setImage(entity.image);

        return model;
    }

    public List<GoodsDetailsModel.Banner> transferBanner(List<GoodsDetailsEntity.Banner> entityList) {
        List<GoodsDetailsModel.Banner> modelList = new ArrayList<>();
        if (entityList == null || entityList.isEmpty()) {
            return modelList;
        }
        for (GoodsDetailsEntity.Banner entity : entityList) {
            modelList.add(transferBanner(entity));
        }

        return modelList;
    }

    public GoodsDetailsModel.Model transferModel(GoodsDetailsEntity.Model entity) {
        GoodsDetailsModel.Model model = new GoodsDetailsModel.Model();
        // 属性id
        model.setId(entity.id);
        // 属性
        model.setImage(entity.image);
        // Propertyid
        model.setContent(entity.content);
        // 图片展示
        model.setPropertyId(entity.propertyId);
        // 展示顺序
        model.setOrder(entity.order);

        return model;
    }

    public List<GoodsDetailsModel.Model> transferModel(List<GoodsDetailsEntity.Model> entityList) {
        List<GoodsDetailsModel.Model> modelList = new ArrayList<>();
        if (entityList == null || entityList.isEmpty()) {
            return modelList;
        }
        for (GoodsDetailsEntity.Model entity : entityList) {
            modelList.add(transferModel(entity));
        }
        return modelList;
    }


    public GoodsDetailsModel.Property transferProperty(GoodsDetailsEntity.Property entity) {
        GoodsDetailsModel.Property model = new GoodsDetailsModel.Property();
        // 属性id
        model.setPropertyId(entity.propertyId);
        // 属性
        model.setContent(entity.content);
        // 子属性列表
        model.setModelList(transferModel(entity.modelList));

        return model;
    }

    public List<GoodsDetailsModel.Property> transferProperty(List<GoodsDetailsEntity.Property> entityList) {
        List<GoodsDetailsModel.Property> modelList = new ArrayList<>();
        if (entityList == null || entityList.isEmpty()) {
            return modelList;
        }
        for (GoodsDetailsEntity.Property entity : entityList) {
            modelList.add(transferProperty(entity));
        }
        return modelList;
    }

    public GoodsDetailsModel.IntroduceImage transferIntroduceImage(GoodsDetailsEntity.IntroduceImage entity) {
        GoodsDetailsModel.IntroduceImage model = new GoodsDetailsModel.IntroduceImage();
        model.setImage(entity.image);
        model.setImageId(entity.imageId);

        return model;
    }

    public List<GoodsDetailsModel.IntroduceImage> transferIntroduceImage(List<GoodsDetailsEntity.IntroduceImage> entityList) {
        List<GoodsDetailsModel.IntroduceImage> models = new ArrayList<>();
        if (entityList == null || entityList.isEmpty()) {
            return models;
        }
        for (GoodsDetailsEntity.IntroduceImage entity : entityList) {
            models.add(transferIntroduceImage(entity));
        }
        return models;
    }

    public GoodsDetailsModel transfer(GoodsDetailsEntity entity) {
        GoodsDetailsModel model = new GoodsDetailsModel();
        // 商品id
        model.setGoodsId(entity.result.goodsId);
        // 隶属商铺id
        model.setShopId(entity.result.shopId);
        // 商品名称
        model.setGoodsName(entity.result.goodsName);
        // 商铺名称
        model.setShopName(entity.result.shopName);
        // 店铺主人名称
        model.setShopOwner(entity.result.shopOwner);
        // 店铺主人签名
        model.setShopOwnerSign(entity.result.shopOwnerSign);
        // 店铺主人头像
        model.setShopOwnerHead(entity.result.shopOwnerHead);
        // 店铺主人id
        model.setShopOwnerId(entity.result.shopOwnerId);
        // 运费
        model.setFreight(entity.result.freight);
        // 详情介绍
        model.setIntroduce(entity.result.introduce);
        // 封面图片地址
        model.setCoverImage(entity.result.coverImage);
        // 是否可以购买， 0-否 1-是
        model.setIsBuyable(entity.result.isBuyable == 1);
        // 总收藏数
        model.setTotalCollected(entity.result.totalCollected);
        // 是否被收藏，0-否 1-是
        model.setIsCollected(entity.result.isCollected == 1);
        // 总商品类型
        model.setTotalProductProperty(entity.result.totalProductProperty);
        // 库存
        model.setSkuList(transferSku(entity.result.skuList));
        // 轮播图
        model.setBannerList(transferBanner(entity.result.bannerList));
        // 商品属性列表
        model.setPropertyList(transferProperty(entity.result.propertyList));
        //商品详情列表
        model.setIntroduceImageList(transferIntroduceImage(entity.result.introduceImageList));

        return model;
    }

}
